#version 450

layout(location=0) in vec3 v_Normal;
layout(location=1) in vec2 v_Texcoord;
layout(location=2) in vec3 v_LightVec;
layout(location=3) in vec3 v_ViewVec;
layout(location=4) in float v_LodBias;

layout(set=0, binding=1) uniform sampler2D u_texture;

layout(location=0) out vec4 fragColor;

void main() {
    vec4 color = texture(u_texture, v_Texcoord, v_LodBias);

    vec3 N = normalize(v_Normal);
    vec3 L = normalize(v_LightVec);
    vec3 V = normalize(v_ViewVec);
    vec3 R = reflect(-L, N);

    vec3 diffuse = max(dot(L, N), 0.0) * color.rgb;
    vec3 specular = pow(max(dot(V, R), 0.0), 16.f) * vec3(0.75f);

    fragColor = vec4(diffuse + specular, color.a);
}